package com.zeratul.common.event.core.handler.local.config;

import com.zeratul.common.event.base.BasePublishHandler;
import com.zeratul.common.event.base.BaseSubscribeHandler;
import com.zeratul.common.event.core.apply.subscribe.IZtEventHandler;
import com.zeratul.common.event.core.handler.local.SpringEventPublishHandler;
import com.zeratul.common.event.core.handler.local.SpringEventSubscribeHandler;
import com.zeratul.common.event.core.server.publish.inter.DelayMessageProducerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

@AutoConfiguration
@Slf4j
@ConditionalOnProperty(prefix = "zt-event", value = "type", havingValue = "local", matchIfMissing = true)
@Import(DelayMessageProducerInterceptor.class)
public class SpringEventHandlerAutoConfiguration {

    /**
     * 发布者处理器
     */
    @Bean
    public BasePublishHandler getSpringEventPublishHandler(){
        log.debug("【事件总线】基于SpringEvent的事件发布者加载...");
        return new SpringEventPublishHandler();
    }

    /**
     * 订阅者处理器
     */
    @Bean
    @ConditionalOnBean(IZtEventHandler.class)
    public BaseSubscribeHandler getSpringEventSubscribeHandler(){
        log.debug("【事件总线】基于SpringEvent的事件订阅者加载...");
        return new SpringEventSubscribeHandler();
    }
}
